package com.admin.mapper;

import com.admin.entity.Admin;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author marisheng
 * @since 2019-11-21
 */
public interface AdminMapper extends BaseMapper<Admin> {

    @Select("SELECT * from admin where admin_parent = ( SELECT admin_id from admin where admin_id =#{admin_id})")
    List<Admin> selshangjiuser(@Param("admin_id")int admin_id);
    List<String> getPermissionByUsername(@Param("username") String id);

    /**
     * 查询是否是 0 管理员
     * @return
     */
    @Select("select * from admin where admin_id=#{admin_id}")
    public Admin queryAdminParent(@Param("admin_id") Integer admin_id);

    int adduser(Admin admin);

    IPage searchadminWithrole(Page p , @Param("m") Map m);



    /**
     * 根据父级id查询子级
     * @param ids
     * @return
     */
    @Select("select * from admin where admin_id in (${ids})")
    List<Admin> getxiajiyonghubyid(String ids);

     public IPage getAllByAdmin(Page p);


    /**
     * 获取当前用户所有子用户的id,包含自己
     * @param id
     * @return   1,2,3这样ID格式
     */
    @Select("select getAllUsers(#{id})")
    String getAllChildUser(int id);

    @Select("select admin_name from admin where admin_name=#{adminName}")
    Admin seladminName(String adminName);

    List updateselct(@Param("m") Map map);


    @Update("UPDATE admin SET admin_last_login_time = #{adminLastLoginTime} where admin_id = #{adminId}")
    int updataNowString(@Param("adminLastLoginTime") String nowString , @Param("adminId") int adminId);

    @Update("UPDATE admin SET admin_password = #{adminPassword} where admin_name = #{adminName}")
    int updatapasswordbyadminName(@Param("adminPassword") String password ,@Param("adminName") String adminName );

    @Select("select admin_password from admin where admin_name=#{adminName}")
    List<Admin> selctyuanpassword(@Param("adminName") String adminName);

    /**
     * 根据站点ID 查询 所属用户
     * @return
     */
    @Select("select admin_id from admin,station where admin_id=station_admin_id and station_id=#{station_id}")
    public Integer queryAdminId(@Param("station_id") Integer station_id);

}
